package com.huadao.pda.me;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.huadao.pda.R;
import com.huadao.pda.base.BaseFragment;
import com.huadao.pda.base.BasePresenter;
import com.huadao.pda.common.dialog.DialogFragmentHelper;
import com.huadao.pda.common.dialog.IDialogResultListener;
import com.huadao.pda.data.bean.DeviceInfo;
import com.huadao.pda.data.bean.Dispensing;
import com.huadao.pda.login.LoginActivity;
import com.huadao.pda.main.PdaApplication;

import butterknife.BindView;
import butterknife.OnClick;

public class MineFrag extends BaseFragment implements MineContract.IMineView {
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_email)
    TextView tvEmail;
    @BindView(R.id.tv_deviceName)
    TextView tvDeviceName;
    @BindView(R.id.tv_deviceNumber)
    TextView tvDeviceNumber;
    @BindView(R.id.tv_MacAddress)
    TextView tvMacAddress;
    @BindView(R.id.tv_ip)
    TextView tvIp;
    @BindView(R.id.tv_port)
    TextView tvPort;

    private MinePresenter presenter;

    @Override
    public int getContentViewId() {
        return R.layout.frag_mine;
    }

    @Override
    protected void initAllMembersView(Bundle savedInstanceState) {
        presenter=new MinePresenter(this);
        DeviceInfo deviceInfo=PdaApplication.getInstance().getDeviceInfo();
        if(deviceInfo!=null){
            if(!TextUtils.isEmpty(deviceInfo.getDeviceName())) {
                tvDeviceName.setText(deviceInfo.getDeviceName());
            }else {
                tvDeviceName.setText(R.string.noValue);
            }
            if(!TextUtils.isEmpty(deviceInfo.getDeviceId())) {
                tvDeviceNumber.setText(deviceInfo.getDeviceId());
            }else {
                tvDeviceNumber.setText(R.string.noValue);
            }
            if(!TextUtils.isEmpty(deviceInfo.getMacAddress())) {
                tvMacAddress.setText(deviceInfo.getMacAddress());
            }else {
                tvMacAddress.setText(R.string.noValue);
            }
            if(!TextUtils.isEmpty(deviceInfo.getIpAddress())) {
                tvIp.setText(deviceInfo.getIpAddress());
            }else {
                tvIp.setText(R.string.noValue);
            }
            if(!TextUtils.isEmpty(deviceInfo.getProt())) {
                tvPort.setText(deviceInfo.getProt());
            }else {
                tvPort.setText(R.string.noValue);
            }
        }

//        tvName.setText("细胞制备"+deviceInfo.get);
        tvEmail.setText(PdaApplication.getInstance().getUserName());
    }

    @Override
    protected BasePresenter getPresenter() {
        return presenter;
    }

    @OnClick(R.id.btn_logout)
    public void onViewClicked() {
        DialogFragmentHelper.showConfirmDialog(getActivity(), "", "确认退出？", new IDialogResultListener<Integer>() {
            @Override
            public void onDataResult(Integer result) {
                if(result==DialogInterface.BUTTON_POSITIVE){
                    Intent intent=new Intent(getActivity(),LoginActivity.class);
                    startActivity(intent);
                    getActivity().finish();
                }
            }
        },true);
    }
}
